﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime.Serialization.Json;

public partial class backmanage_API_A_Newsclass : System.Web.UI.Page
{
    /// <summary>
    /// NEWSSYSTEM NEWSCLASS.API 新闻系统API
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        string returnStr = string.Empty;
        string editType = Request.Params["edit"];//操作类别
        switch (editType)
        {
            case "add":
                {
                    returnStr = NewsclassAdd();
                    break;
                }
            case "del":
                {
                    returnStr = NewsclassDel();
                    break;
                }
            case "update":
                {
                    returnStr = NewsclassUpdate();
                    break;
                }
            case "list":
                {
                    returnStr = NewsclassList();
                    break;
                }
            default:
                {
         
                    break;
                }
        }
        Response.Write(returnStr);
    }
    /// <summary>
    /// 添加类别
    /// </summary>
    /// <returns></returns>
    protected string NewsclassAdd()
    {
        MODEL.NewsColumn model = new MODEL.NewsColumn();
        BLL.NewsColumn bll = new BLL.NewsColumn();
        model.NclassName = Request.Params["classname"].ToString();
        model.Nreadme = Request.Params["readme"].ToString();
        model.NparentID = 0;
        model.Ndepth = 0;
        model.NrootID = 0;
        model.NchildNum = 0;
        model.NprevID = 0;
        model.NnextID = 0;
        model.NorderID = 0;
        model.NparentPath = "0";
        return bll.NewsColumnAdd(model).ToString().ToLower();
    }
    /// <summary>
    /// 删除类别
    /// </summary>
    /// <returns></returns>
    protected string NewsclassDel()
    {
        string[] idList = Request.Params["columnId[]"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        string errId = string.Empty;
        for (int i = 0; i < idList.Length; i++)
        {
            BLL.NewsColumn bll = new BLL.NewsColumn();
            int columnId = Convert.ToInt32(idList[i]);
            bool flag = bll.NewsColumnDel(columnId);
            if (flag)
            {
                errId = "True";
            }
            else
            {
                errId += idList[i] + ",";
            }
        }
        return errId;

    }
    /// <summary>
    /// 修改类别
    /// </summary>
    /// <returns></returns>
    protected string NewsclassUpdate()
    {
        MODEL.NewsColumn model = new MODEL.NewsColumn();
        BLL.NewsColumn bll = new BLL.NewsColumn();
        model.NclassID = Convert.ToInt32(Request.Params["classid"]);
        model.NclassName = Request.Params["classname"].ToString();
        model.Nreadme = Request.Params["readme"].ToString();
        model.NparentID = 0;
        model.Ndepth = 0;
        model.NrootID = 0;
        model.NchildNum = 0;
        model.NprevID = 0;
        model.NnextID = 0;
        model.NorderID = 0;
        model.NparentPath = "0";
        return bll.NewsColumnUpdate(model).ToString().ToLower();
    }
    /// <summary>
    /// 类别列表
    /// </summary>
    /// <returns></returns>
    protected string NewsclassList()
    {
        BLL.NewsColumn bll = new BLL.NewsColumn();
        DataSet ds = bll.GetNewsColumnList();
        StringBuilder htmlStr = new StringBuilder();
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            htmlStr.Append("<tr id=\"" + dr["Nclassid"].ToString() + "\">");
            htmlStr.Append("<td><input type=\"checkbox\" value=\""+dr["Nclassid"].ToString()+"\"/></td>");
            htmlStr.Append("<td><div id=\"div" + dr["Nclassid"].ToString() + "\">");
            htmlStr.Append("<input type=\"text\" readonly=\"readonly\" class=\"tableinput\" value=\"" + dr["Nclassname"].ToString() + "\" />");
            htmlStr.Append("<a href=\"#\" class=\"aclass\">修改</a>");
            htmlStr.Append("<a href=\"#\" class=\"aaclass\" title=\"save\">保存</a>");
            htmlStr.Append("<a href=\"#\" class=\"aaclass\" title=\"esc\">取消</a>");
            htmlStr.Append("</td>");
            htmlStr.Append("<td><div id=\"divr" + dr["Nclassid"].ToString() + "\">");
            htmlStr.Append("<input type=\"text\" readonly=\"readonly\" class=\"tableinput\" value=\"" + dr["Nreadme"].ToString() + "\" />");
            htmlStr.Append("<a href=\"#\" class=\"aclass\">修改</a>");
            htmlStr.Append("<a href=\"#\" class=\"aaclass\" title=\"save\">保存</a>");
            htmlStr.Append("<a href=\"#\" class=\"aaclass\" title=\"esc\">取消</a>");
            htmlStr.Append("</td>");
            htmlStr.Append("</tr>");
        }
        return htmlStr.ToString();
    }
}

